package net.mingsoft.report_data.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * @author gengfa
 * @date 22/03/17
 */
public class HainanAreaUtil {

    private HainanAreaUtil() {}

    private static final String[] AREAS  = new String[]{"海口", "美兰区", "龙华区", "秀英区", "琼山区", "文昌", "澄迈", "定安", "儋州", "临高", "昌江", "东方", "五指山", "琼中", "屯昌", "白沙", "琼海", "万宁", "三亚", "陵水", "保亭", "乐东", "三沙"};
    private static final String[] NORTH  = new String[]{"海口", "定安", "美兰区", "龙华区", "秀英区", "琼山区", "文昌", "澄迈"};
    private static final String[] WEST   = new String[]{"儋州", "临高", "昌江", "东方"};
    private static final String[] MIDDLE = new String[]{"五指山", "琼中", "屯昌", "白沙"};
    private static final String[] EAST   = new String[]{"琼海", "万宁"};
    private static final String[] SOUTH  = new String[]{"三亚", "陵水", "保亭", "乐东", "三沙"};

    public static String getType(String area) {
        int index = findIndex(area);

        if (index == -1) {
            return "未知区域";
        }

        if (index < 8) {
            return "北部区域";
        } else if (index < 12) {
            return "西部区域";
        } else if (index < 16) {
            return "中部区域";
        } else if (index < 18) {
            return "东部区域";
        } else {
            return "南部区域";
        }
    }

    private static int findIndex(String area) {
        for (int i = 0; i < AREAS.length; i++) {
            if (StringUtils.equals(area, AREAS[i]) || StringUtils.contains(area, AREAS[i])) {
                return i;
            }
        }
        return -1;
    }
}
